package antcraft;

import java.awt.*;

public class PheromoneCanvas extends Canvas {
	static final long serialVersionUID = 1;
	
	Vector2D m_parent;
	static final int blockSize = 20;
	
	public PheromoneCanvas( Vector2D parent, double size ) {
		m_parent = parent;
	}
	
	public void paint( Graphics g ) {
		double magnitude = m_parent.magnitude();
		double direction = m_parent.direction();

		int alpha = Math.min( 255, (int) (magnitude / 5) );

		int xPoints[] = new int[3];
		int yPoints[] = new int[3];
		
		// Point 1 -- arrow tip
		xPoints[0] = (blockSize / 2) + (int) ( (blockSize / 2) * Math.cos( direction ) );
		yPoints[0] = (blockSize / 2) + (int) ( (blockSize / 2) * Math.sin( direction ) );
		
		// Point 2 -- bottom left (tip - 7/8 PI)
		xPoints[1] = (blockSize / 2) + (int) ( (blockSize / 2) *
				Math.cos( direction - ( (7/8) * Math.PI ) ) );
		yPoints[1] = (blockSize / 2) + (int) ( (blockSize / 2) *
				Math.sin( direction - ( (7/8) * Math.PI ) ) );

		// Point 3 -- bottom right (tip + 7/8 PI)
		xPoints[2] = (blockSize / 2) + (int) ( (blockSize / 2) *
				Math.cos( direction + ( (7/8) * Math.PI ) ) );
		yPoints[2] = (blockSize / 2) + (int) ( (blockSize / 2) *
				Math.sin( direction + ( (7/8) * Math.PI ) ) );

		Polygon arrow = new Polygon();

		g.setColor( new Color( 0, 0, 255, alpha ) );
		g.fillPolygon( arrow );
	}
}
